<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表页</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>
<body>
    <!-- 导航栏. nav 是 导航 这个词的缩写 -->
    <div class="nav">
        <!-- logo -->
        <img src="image/logo2.jpg" alt="">
        <div class="title">zzzyh的博客系统</div>
        <!-- 只是一个空白, 用来把后面的链接挤过去 -->
        <!-- 这是一个简单粗暴的写法~~ -->
        <div class="spacer"></div>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <!-- 这里的地址回头再说 -->
        <a href="logout">注销</a>
    </div>

    <!-- 页面的主体部分 -->
    <div class="container">
        <!-- 左侧信息 -->
        <div class="container-left">
            <!-- 这个 div 表示整个用户信息的区域 -->
            <div class="card">
                <!-- 用户的头像 -->
                <img src="image/kun.jpg" alt="">
                <!-- 用户名 -->
                <h3></h3>
                <!-- github 地址 -->
                <!--<a href="https://www.github.com">github 地址</a>-->
                <!-- 统计信息 -->
                <!--<div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span>2</span>
                    <span>1</span>
                </div>-->
            </div>
        </div>
        <!-- 右侧信息 -->
        <div class="container-right">
            <!-- <div class="blog">
                <div class="title">我的第一篇博客</div>
                <div class="date">2023-05-11 20:00:00</div>
                <div class="desc">
                    从今天起, 我要认真敲代码. Lorem ipsum dolor sit amet consectetur, adipisicing elit. Debitis repellendus voluptatum, reiciendis rem consectetur incidunt aspernatur eveniet excepturi magni quis sint, provident est at et pariatur dolorem aliquid fugit voluptatem.
                </div>
                <a href="blog_detail.html?blogId=1">查看全文 &gt;&gt; </a>
            </div> -->
            
        </div>
    </div>

    <script src="js/app.js"></script>
    <script>
        function findAll(){
            $.ajax({
                url:'findAll',
                type:'get',
                success:function(body){
                    let conDiv = document.querySelector('.container-right');
                    for(let i = 0; i<body.length;i++){
                        let blogDiv = document.createElement('div');
                        blogDiv.className='blog';
                        let blog = body[i];

                        let blogTitle = document.createElement('div');
                        blogTitle.className='title';
                        blogTitle.innerHTML=blog.title;

                        let blogDate = document.createElement('div');
                        blogDate.className='date';
                        blogDate.innerHTML=blog.postTime;

                        let blogDesc = document.createElement('div');
                        blogDesc.className='desc';
                        blogDesc.innerHTML=blog.content;

                        let more = document.createElement('a');
                        more.innerHTML='查看全文 &gt;&gt; ';
                        more.href='blog_detail.html?blogId='+blog.blogid;


                        let rm = document.createElement('a');
                        rm.innerHTML='删除博客';
                        rm.href='delete?blogId='+blog.blogid;


                        blogDiv.appendChild(blogTitle);
                        blogDiv.appendChild(blogDate);
                        blogDiv.appendChild(blogDesc);
                        blogDiv.appendChild(more);
                        blogDiv.appendChild(rm);
                        
                        conDiv.appendChild(blogDiv)
                    }
                }
            });
        };
        findAll();
        isLogin();

        function getuser(){
            $.ajax({
                type:'get',
                url:'getuser',
                success:function(date){
                    let h3 = document.querySelector('.card h3');
                    h3.innerHTML=date.username;
                    
                }
            });
        };
        getuser();
    </script>
</body>
</html>